#include "example_diagramscene.h"
#include "example_nodes.h"


ExampleDiagramScene::ExampleDiagramScene(QMenu *itemMenu, QObject* parent  ) : DiagramScene(itemMenu, parent ), mode(0) {
}

void ExampleDiagramScene:: mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) {
    if (mode == 0) {
        DiagramScene::mousePressEvent(mouseEvent);
    }
    else {
        NodeItem *node2 = createNode(mode);
        //this->addItem(node2);
        node2->setPos(mouseEvent->scenePos());
       mode = 0;
    }
}

ExampleBaseNode* ExampleDiagramScene::createNode(int type) {
    ExampleBaseNode *node2 = NULL;
    switch (type) {
    case 1:
        node2 = new ExampleNode1(mItemMenu,NULL,this);
        break;
    case 2:
        node2 = new ExampleNode2(mItemMenu,NULL,this);
        break;
    case 5:
        node2 = new ExampleNode5(mItemMenu,NULL,this);
        break;
    case 6:
        node2 = new ExampleNode6(mItemMenu,NULL,this);
        break;
    case 7:
        node2 = new ExampleNode7(mItemMenu,NULL,this);
        break;
    case 8:
        node2 = new ExampleNode8(mItemMenu,NULL,this);
        break;
    }
    emit nodeItemInserted(node2);
    return node2;
}
